package com.example.controller;

import com.example.common.Result;
import com.example.entity.ClassInfo;
import com.example.entity.XuankeInfo;
import com.example.service.XuankeInfoService;
import com.github.pagehelper.PageInfo;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

@RestController
@RequestMapping("/xuankeInfo")
public class XuankeInfoController {
    @Resource
    private XuankeInfoService xuankeInfoService;


    @GetMapping("/page")
    public Result findPage(@RequestParam Integer pageNum, @RequestParam Integer pageSize,HttpServletRequest request){
        PageInfo<XuankeInfo> info = xuankeInfoService.findPage(pageNum,pageSize,request);
        return Result.success(info);
    }

    @GetMapping("/page/{name}")
    public Result findPageName(@RequestParam Integer pageNum, @RequestParam Integer pageSize, @PathVariable String name, HttpServletRequest request){
        //PageInfo<XuankeInfo> info = xuankeInfoService.findPageName(pageNum,pageSize,name);
        PageInfo<XuankeInfo> info = xuankeInfoService.findPageName(pageNum,pageSize,name,request);
        return Result.success(info);
    }
    @DeleteMapping("/{id}")
    public Result deleteById(@PathVariable(value = "id") Long id){
        xuankeInfoService.deleteById(id);
        return Result.success();
    }
    @PutMapping
    public Result update(@RequestBody XuankeInfo xuankeInfo){
        xuankeInfoService.update2(xuankeInfo);
        return Result.success();
    }

}
